﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace RoboTrocity.Code.GameStates {
	public abstract class GameState {
		protected KeyboardState keyState, prevKeyState;
		protected MouseState mouseState, prevMouseState;
		public delegate void PushState(GameState stateToPush);
		public delegate void PopState();

		public PushState pushState;
		public PopState popState;

		protected GameState(PushState pushS, PopState popS) {
			pushState = new PushState(pushS);
			popState = new PopState(popS);

		}

		

		public abstract void ProcessInput(KeyboardState kState, KeyboardState prevKState, MouseState mState, MouseState prevMState);
		public abstract void Update(float elapsed);
		public abstract void Draw(SpriteBatch sBatch);
		
		/// <summary>
		/// Whether or not you can see through this state layer.
		/// </summary>
		/// <returns>True if you can see through.</returns>
		public virtual bool DrawThrough {
			get { return false; }
		}

		/// <summary>
		/// Whether or not inputs from this layer are also processed in the lower layers.
		/// </summary>
		/// <returns>True if input is processed in lower GameStates.</returns>
		public virtual bool ProcessThrough {
			get { return false; }
		}

		/// <summary>
		/// Whether or not GameStates below this one will update.
		/// </summary>
		/// <returns>True if lower layers below this also update.</returns>
		public virtual bool UpdateThrough {
			get { return false; }
		}


		/// <summary>
		/// Determines if a key is pressed.
		/// </summary>
		/// <param name="key">The key being checked.</param>
		/// <param name="canHold">Whether or not to allow the key to be held down.</param>
		/// <returns>Returns true if the key is pressed.</returns>
		protected bool keyIsPressed(Keys key, bool canHold) {
			if (canHold) {
				return keyState.IsKeyDown(key);
			}
			return keyState.IsKeyDown(key) && !prevKeyState.IsKeyDown(key);
		}
	}
}